package net.obxlabs.tweetpad.behaviour;

import java.awt.Color;

import net.nexttext.TextObject;
import net.nexttext.behaviour.standard.*;
import net.nexttext.property.*;

public class ColorizeBack extends Colorize {
	public ColorizeBack() {
		this(Color.BLACK, 10, true, false);
	}
	
	public ColorizeBack(Color color, int speed, boolean fill, boolean stroke) {
		super(color, speed, fill, stroke);
	}
	
	public ActionResult behave(TextObject to) {
        boolean doneFill = false;
        boolean doneStroke = false;
        
        if (applyToFill) {
            doneFill =  fadeTo(to.getColor(), 
                    ((ColorProperty)getColor(to)).getOriginal(), 
                    (int)((NumberProperty)properties().get("SpeedFill")).get());
        }
        
        if (applyToStroke) {
            doneStroke =  fadeTo(to.getStrokeColor(), 
            		((ColorProperty)getColor(to)).getOriginal(), 
                    (int)((NumberProperty)properties().get("SpeedStroke")).get());
        }
        
        if ((applyToFill==doneFill) && (applyToStroke==doneStroke))
            return new ActionResult (true, true, false);
        
        return new ActionResult(false, true, false);
    }
	
	public void setBaseColor(Color newColor) {
		((ColorProperty)properties().get("ColorFill")).set(newColor);
		((ColorProperty)properties().get("ColorStroke")).set(newColor);
	}
}
